#ifndef COMPRESS_H
#define COMPRESS_H
#include <math.h>
#include "heap.h"

typedef struct CharCode
{
	unsigned char val;          //ascll码
	size_t code;                //哈弗曼编码
	size_t cnt;                 //哈弗曼编码长度
}CharCode;

typedef struct Filemsg
{
    long long int sum_word;        //总字节数
    char filename[20];             //文件名
}Filemsg;

typedef struct TreeNode
{
	unsigned char val;
	size_t weight;
	struct TreeNode* left;
	struct TreeNode* right;
}TreeNode;



extern Filemsg filemsg;



int node_cmp(const void* p1,const void* p2);  //比较权重

TreeNode* create_node(unsigned char val,size_t weight);

void _create_code(TreeNode* root,char path,size_t code,int cnt);

void create_code(TreeNode* root);

TreeNode* init_tree(unsigned char* val_arr,size_t* weight_arr,size_t len);   //利用数组创建哈弗曼树

void get_hafftree(FILE* rfp,const char* filename);			//用于读取文件权值并生成对应的hufftree

int compress_file(const char* filename,FILE* rfp);             //压缩

void fwrite_filemsg(const char* filename,FILE* rfp,FILE* wfp);  		//记录文件相关信息

void change_dat(char* dest,const char* filename);			//将压缩文件文件名设置为 源文件名.dat

void change_json(char* dest,const char* filename);			//将压缩文件文件名设置为 源文件名.json

void get_haffcode(const char* filename,unsigned char* val_arr,size_t* weight_arr);			//在解压前拿到haff编码

int dp_file(TreeNode* root,FILE* rfp);    //解压

#endif//COMPRESS_H